﻿using MediatR;
using SuYuanSystem.Applications;
using SuYuanSystem.Domain;
using SuYuanSystem.Repositories;
using SuYuanSystem.WebApi.MedialRs.Commands.Slaughters;

namespace SuYuanSystem.WebApi.MedialRs.CommandHandlers.Slaughters
{
    public class SlaughterQueryCommandsHandlers : IRequestHandler<SlaughterQueryCommands, ApiResult<Slaughter>>
    {
        public SlaughterQueryCommandsHandlers(IRepository<Slaughter> repository)
        {
            Repository = repository;
        }

        public IRepository<Slaughter> Repository { get; }

        public Task<ApiResult<Slaughter>> Handle(SlaughterQueryCommands request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<Slaughter> result = new ApiResult<Slaughter>();
                result.statusCode = StatusCode.Success;
                result.Message = "查询成功";
                var list = Repository.GetAll();
                var entity = list.Result.FirstOrDefault();
                result.Data = entity;
                return Task.FromResult(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
